package com.zhugang.week13.stack;

import java.util.Stack;

/**
 * @program algorithms
 * @description: CQueue
 * @author: chanzhugang
 * @create: 2022/11/01 22:13
 */
public class CQueue {

    /**
     * 剑指offer 09 用两个栈实现队列
     * https://leetcode.cn/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/
     */
    Stack<Integer> stack = new Stack<>();
    Stack<Integer> tempStack = new Stack<>();

    public CQueue() {

    }

    public void appendTail(int value) {
        stack.push(value);
    }

    /**
     * 临时栈最终不存数据，要把数据倒腾回去
     *
     * @return
     */
    public int deleteHead() {
        if (stack.isEmpty()) {
            return -1;
        }
        while (!stack.isEmpty()) {
            tempStack.push(stack.pop());
        }
        Integer pop = tempStack.pop();
        while (!tempStack.isEmpty()) {
            stack.push(tempStack.pop());
        }
        return pop;
    }

}